#!/bin/bash
# SPDX-License-Identifier: LGPL-2.1-or-later
# Ubuntu 24.10 自定义bootloader和shim安装脚本

set -e

echo "Installing custom UEFI bootloader with shim..."

# 创建bootloader配置
mkdir -p /boot/efi/loader/entries

ls -l /boot
# 获取内核版本和根分区UUID
#KERNEL_VERSION=$(ls /boot/vmlinuz-* | head -1 | sed 's/.*vmlinuz-//')
#ROOT_UUID=$(blkid -s UUID -o value $(findmnt -n -o SOURCE /))

# 创建启动配置
#cat > /boot/efi/custom-boot.conf << EOF
#kernel_path=/vmlinuz-${KERNEL_VERSION}
#initrd_path=/initrd.img-${KERNEL_VERSION}
#kernel_options=root=UUID=${ROOT_UUID} ro quiet splash
#EOF

# 设置EFI启动项
efibootmgr --create --disk /dev/sda --part 1 --label "Ubuntu Custom" --loader "\EFI\BOOT\BOOTX64.EFI"

echo "Custom UEFI bootloader with shim installation completed!"
